// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.user-card {
  @top: user-card;
  @avatar-border-radius: 6px;
  @background-color: @osu-colour-b4;
  @background-overlay-fade--online: hsla(var(--hsl-b5), 0.6);
  @background-overlay-fade--offline: hsla(var(--hsl-b5), 0.7);
  @card-border-radius: 10px;
  @fade-duration: 220ms;

  --avatar-size: 60px;
  --card-item-spacing: 10px;
  --icon-gutter: 6px;
  --status-icon-margin: 10px;

  display: inline-block;
  font-family: var(--font-default);

  width: 100%;
  height: @user-card-height;
  background-color: @background-color;
  border-radius: @card-border-radius;
  position: relative;

  overflow: hidden;

  &--list {
    --avatar-size: 40px;

    @media @narrow {
      --card-item-spacing: 6px;
      --icon-gutter: 4px;
      --status-icon-margin: 0;
    }

    height: var(--avatar-size);
    border-radius: @avatar-border-radius;
  }

  .qtip--user-card & {
    width: @user-card-width + 10px;
  }

  &--has-outline::after {
    .@{top}:hover&,
    .@{top}--active& {
      .full-size();
      content: "";
      border: 2px solid @osu-colour-l1;
      border-radius: @card-border-radius;
      pointer-events: none;

      .search-result--user & {
        border-color: @blue-dark;
      }

      .@{top}--list& {
        border-radius: @avatar-border-radius;
      }
    }
  }

  &--highlightable {
    .user-cards--menu-active & {
      pointer-events: none;
    }
  }

  &__avatar {
    .full-size();
    border-radius: @avatar-border-radius;
    object-fit: contain;
    background-color: @background-color;
    transition: opacity ease-in-out @fade-duration;
    opacity: 0;

    &--loaded {
      opacity: 1;
    }

    .@{top}--list & {
      border-radius: @avatar-border-radius 0 0 @avatar-border-radius;
    }
  }

  &__avatar-space {
    width: var(--avatar-size);
    height: var(--avatar-size);
    flex: none;
    position: relative;
  }

  &__avatar-spinner {
    .full-size();
    .center-content();
    border-radius: @avatar-border-radius;
    color: #fff;
    font-size: 14px;
    background: fade(#fff, 10%);
    transition: opacity ease-in-out @fade-duration;
    opacity: 0.25;

    &--loaded {
      // needs display: none or element to be removed to remove the layer in Safari
      // but can't transition a display change...
      opacity: 0;
    }
  }

  &__background {
    // to prevent annoying white-pixel artefacts appearing due to
    // browsers not handling 'overflow: hidden' properly
    border-radius: @card-border-radius;
    .full-size();
    object-fit: cover;
    transition: opacity ease-in-out @fade-duration;

    &--loading {
      opacity: 0;
    }

    .@{top}--list & {
      position: absolute;
      left: unset;
      right: 0;
      width: 50%;
      border-radius: @avatar-border-radius;
    }
  }

  &__background-container {
    .full-size();

    .@{top}--active & {
      pointer-events: none;
    }
  }

  &__background-overlay {
    .full-size();
    border-radius: @card-border-radius;
    background: @background-overlay-fade--offline;

    &--online {
      background: @background-overlay-fade--online;
    }

    .@{top}--list & {
      border-radius: @avatar-border-radius;
      background: linear-gradient(
        to right,
        @osu-colour-b5 50%,
        @background-overlay-fade--offline
      );

      &--online {
        background: linear-gradient(
          to right,
          @osu-colour-b5 50%,
          @background-overlay-fade--online
        );
      }
    }
  }

  &__card {
    .link-white();
    .link-plain();

    display: flex;
    flex-direction: column;
    justify-content: space-between;

    pointer-events: none;

    height: 100%;
    position: relative;

    .@{top}--list & {
      flex-direction: row;
    }
  }

  &__content {
    padding: var(--card-item-spacing);

    &--details {
      display: grid;
      grid-template-columns: minmax(min-content, auto) 1fr;
    }

    &--status {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      padding-top: 0;
    }

    .@{top}--list & {
      padding: 0;
    }
  }

  &__details {
    display: grid;
    grid-template-rows: @user-card-icon-size 1fr;
    margin-left: var(--card-item-spacing);

    .@{top}--list & {
      grid-gap: var(--card-item-spacing);
      grid-template-rows: unset;
      grid-template-columns: auto repeat(2, min-content);
    }
  }

  &__group-badge {
    margin-left: 2px;
  }

  &__group-badges {
    display: flex;
    margin-left: 3px;
    pointer-events: auto;
  }

  &__icon {
    display: flex;
    pointer-events: auto;

    a& {
      .link-plain();
    }

    & + & {
      margin-left: var(--icon-gutter);
    }

    .user-cards--menu-active & {
      pointer-events: none;
    }

    &:empty {
      display: none;
    }

    &--flag {
      font-size: @user-card-icon-size; // icon size
    }

    &--menu {
      .circle(25px);
      font-size: 10px;
      background-color: @osu-colour-b6;
      opacity: 0;
      transition: background-color 120ms ease-in-out;
      position: relative;

      // NB: there is a issue where clicking on the button to close the menu
      // causes the state to momentarily unhover and rehover
      .@{top}:hover & {
        opacity: 1;

        &:hover {
          background-color: @osu-colour-l1;
        }
      }

      // needs the higher specificity over .@{top}:hover
      .@{top}--active && {
        opacity: 1;
        background-color: @osu-colour-l1;
      }

      .@{top}--list & {
        transition: none;
        opacity: 1;
        border-radius: 0 @card-border-radius @card-border-radius 0;
        background-color: transparent;
        width: 20px;
        height: var(--avatar-size);
      }
    }
  }

  &__icons {
    display: flex;
    flex: none;

    .@{top}--list &--card {
      @media @narrow {
        display: none;
      }
    }

    .@{top}--list & {
      align-items: center;
    }
  }

  &__status {
    display: flex;
    align-items: center;

    min-width: 0;
  }

  &__status-icon {
    .circle(25px);
    border: solid 4px #000;

    &--online {
      border: solid 4px @green-light;
    }
  }

  &__status-icon-container {
    .center-content();
    flex: none;
    // TODO: put in grid instead?
    width: var(--avatar-size);

    .@{top}--list & {
      order: 1;
      width: unset;
      margin: 0 var(--status-icon-margin);
    }
  }

  &__status-message {
    &--sub {
      font-size: 12px;
    }

    @media @mobile {
      display: none;
    }
  }

  &__status-messages {
    display: flex;
    flex-direction: column;
    margin-left: var(--card-item-spacing);

    font-size: 14px;
    min-width: 0;

    .@{top}--list & {
      text-align: right;
    }

    @media @narrow {
      display: none;
    }
  }

  &__user {
    display: flex;
    align-items: center;

    height: var(--avatar-size);
    min-width: 0;
  }

  &__username {
    .link-white();
    .link-plain();
    pointer-events: auto;
  }

  &__username-row {
    display: flex;
    align-items: center;
    min-width: 0;
    font-weight: 600;
  }
}
